namespace TomatoBreak.DomainObjects
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;

    [DebuggerDisplay("{User.Name}-{CreatedAt}")]
    public class ToDoList : Entity
    {
        private User user;
        private DateTime createdAt;
        private IList<ToDoItem> items;

        [Obsolete("Used by the ORM")]
        public ToDoList()
        {
        }

        public ToDoList(User user, DateTime createdAt)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            this.user = user;
            this.createdAt = createdAt;
        }

        public virtual DateTime CreatedAt
        {
            [DebuggerStepThrough]
            get { return createdAt; }

            [DebuggerStepThrough]
            protected set { createdAt = value; }
        }

        public virtual User User
        {
            [DebuggerStepThrough]
            get { return user; }

            [DebuggerStepThrough]
            protected set { user = value; }
        }

        public virtual IEnumerable<ToDoItem> Items
        {
            [DebuggerStepThrough]
            get { return items ?? (items = new List<ToDoItem>()); }
        }

        public virtual ToDoItem AddItem(int orderNo, Task task)
        {
            ToDoItem item = new ToDoItem(orderNo, task, this);

            ((ICollection<ToDoItem>)Items).Add(item);

            return item;
        }
    }
}